package com.sys.controller;

import com.sys.pojo.User;
import com.sys.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.Date;
import java.util.List;

@Controller
public class UserController {
    @Autowired
    private UserService userService;

    /**
     * 请求URL:http://localhost:8080/user
     * 响应路径：/WEB-INF/jsp/user.js.jsp
     */
    @RequestMapping("user")
    public String user(){
        //int num = 100/0;
        return "user";
    }

    /**
     * 请求URL:http://localhost:8080/getAll
     * 响应路径：/WEB-INF/jsp/user.js.jsp
     * 数据：List<User>
     */
    @RequestMapping("getAll")
    @ResponseBody
    public List<User> getAll()throws Exception{
        return userService.getAll();
    }
    @RequestMapping("useradd")
    public String useradd(){
        return "useradd";
    }

    @RequestMapping(value = "/user/add",method = RequestMethod.POST,produces = "application/json;charset=utf-8")
    @ResponseBody
    public User add(User user){
        System.out.println(user.getAddress()+","+user.getBirthday());
        user.setCreatedBy(1);
        user.setCreationDate(new Date());
        return user;
    }
}
